<?php
namespace backend\models;

use Yii;
use yii\base\Model;
use yii\web\UploadedFile;

/**
 * UploadForm is the model behind the upload form.
 */
class UploadFlashForm extends Model
{
	/**
	 * @var UploadedFile file attribute
	 */
	public $image_upload;
	public $name;
	/**
	 * item_preview
	 */
	public $item_id;
	public $fid;
	public $mid;
	public $img_small_id;
	public $img_thumb_id;
	public $img_url_id;
	
	public $pid;
	public $model_p;
	
	public $id;
	
	public $file;
	
	public $image_typeid;
	
	public $url;
	/**
	 * @return array the validation rules.
	 */
	public function rules()
	{
		
		return [
		[['image_upload'], 'image','extensions' => 'png,jpg,jpeg,gif,bmp','maxWidth'=>'2000','maxHeight'=>'2000',
		'overWidth'=>'宽必须低于2000像素','overHeight'=>'高必须低于2000像素'],
		['name','string'],
		   [['file','image_upload','name'],'safe'],
		[['item_id', 'fid', 'mid', 'pid', 'image_typeid'], 'integer'],
		[['item_id','image_typeid'], 'required'],
		
		//[['fid', 'mid', 'item_id'], 'unique', 'targetAttribute' => ['fid','mid','item_id'],
		//'targetClass' => ItemPreview::className(),
		// 'message' => Yii::t('app','The combination of Item ID, Fid and Mid has already been taken.')]	
		
		];
	}
	public function attributeLabels()
	{
		return [
			'image_upload' => Yii::t('app','Image File'),
		    'file' => Yii::t('app','Image File'),
			'name' => Yii::t('app','Image Name'),
			'fid' => Yii::t('app','Fid'),
			'mid' => Yii::t('app','Mid'),
			'image_typeid' => Yii::t('app','image_typeid'),
		];
	}
	public function scenarios()
	{
		$scenarios = parent::scenarios();
		$scenarios['no_need_file_name'] = ['image_upload'];
		$scenarios['need_file_name'] = ['image_upload', 'name'];
		$scenarios['item_preview'] = ['image_upload','item_id', 'fid', 'mid'];
		$scenarios['item_preview_angle'] = ['image_upload'];
		$scenarios['upload_img'] = ['image_upload', 'name'];
		$scenarios['item_preview_tz'] = ['image_upload','image_typeid'];
		return $scenarios;
	}
	public function getModel()
	{
		return $this->model_p = ItemPreview::find()->all();
	}
	public function find($model,$fid,$mid,$item_id)
	{
	
		
		$model->andWhere(['fid','mid','item_id']);
		return $query;
	}
	
}